<?php
session_save_path('sessions');
session_start();

// Include the different user types so we can filter out unauthorized users
include("include/dbUserTypes.php");

// Include our user class
include_once("include/user.php");

// Our admin navigation menu function
include("include/admin/adminNavigation.php");

// Create a variable to store our user if we're validated
$user = null;

// Check if we're in a valid session. If not, go back to main login page.
if( !isset($_SESSION['user']) || $_SESSION['user'] == null ) {
    header("location:main_login.php");
}
else {
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);
}

// If we're not an admin go back to the user redirection page
if( $user->getUserType() != $USERTYPE_ADMIN )
    header("location:login_success.php");

// Include the header (CSS files, etc)
include("include/header.php"); ?>

<body>
  <div id="wrapper">
    <div id="header"> </div>
    <div id="left">
      <div id="logo">
        <h1>Home Sale</h1>
        <p>Only By Owner</p>
      </div>
      <div id="nav">
        <?php addNavigation(2)?>
      </div>
    </div>
    <div id="rightAdmin">
      <h2>Monitor Listings</h2>
      <div id="welcome">
       <?php if(isset($_SESSION['updateSuccess'])) {
            ?><div id="error"><?php echo $_SESSION['updateSuccess'];?></div>
            <?php
                unset($_SESSION['updateSuccess']);
            
            }
         
            if( isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0 )
                include("include/admin/editListing.php");
            else
                include("include/admin/manageListings.php"); 
        ?>
      </div>
      <div class="clear"> </div>
    </div>
    <div class="clear"> </div>
    <div id="spacer"> </div>
    <div id="footer">
      <div id="copyright">
        &copy; Template taken from http://www.freewebsitetemplates.com/
      </div>
	  <div id="footerline"></div>
    </div>
	
  </div>
</body>
</html>